<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>数据统计 -- 订单结算情况统计</title>
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap.min.css">
    <link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="${contextPath}/static/layer/css/layui.css">
    <script src="${contextPath}/static/statistics/js/jquery.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
    <script src="${contextPath}/static/statistics/js/vue.js"></script>
    <script src="${contextPath}/static/statistics/js/echarts.min.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
    <script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
    <style>
        .autocomplete-suggestions {
            border: 1px solid #999;
            background: #FFF;
            overflow: auto;
        }

        .autocomplete-suggestion {
            padding: 2px 5px;
            white-space: nowrap;
            overflow: hidden;
        }

        .autocomplete-selected {
            background: #F0F0F0;
        }

        .autocomplete-suggestions strong {
            font-weight: normal;
            color: #3399FF;
        }
    </style>
</head>
<body style="background: rgba(119, 118, 118, 0.15);">
<div class="container-fluid" id="app">
    <form class="form-inline" style="margin-top: 50px; margin-bottom: 5px;">
        <div class="form-group">
            <input type="text" class="form-control" id="turnCreateDate" placeholder="查询开始时间">
        </div>
        <div class="form-group">
            <input type="text" class="form-control" id="bindCreateDate" placeholder="查询结束时间">
        </div>
        <button type="button" class="btn btn-success" onclick="queryOrder();">查询</button>
        <button type="button" title="根据查询条件导出所有记录" onclick="exportExcel();"
                class="btn btn-info">导出Excel
        </button>
    </form>
    <div class="row" style="background-color: rgb(53, 147, 202);margin-right: 0px;margin-left: 0px; height: 37px;">
        <div class="col-sm-10" style="margin-top: 6px;">
            <strong style="font-size: 18px;color: #f9f9f9;">订单结算情况统计</strong>
        </div>
        <div class="col-sm-2" style="text-align: right">

        </div>
    </div>
    <div class="table-responsive" id="tableContainer" style="height: 410px">
        <table class="table table-striped table-condensed table-bordered">
            <thead style="background-color:#eee;">
            <tr>
                <th>区域</th>
                <th>应结笔数</th>
                <th>应结算金额</th>
                <th>结算成功笔数</th>
                <th>结算成功金额</th>
                <th>成功率</th>
                <th>失败笔数</th>
                <th>结算失败金额</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            <tr v-for="(order,index) in orderList">
                <td>{{order.shortName}}</td>
                <td>{{order.orderNo}}</td>
                <td>{{order.ordAmtSum.toFixed(2)}}</td>

                <td>{{order.successOrderNo}}</td>
                <td>{{order.successOrdAmtSum.toFixed(2)}}</td>
                <td>{{((order.successOrderNo / order.orderNo) * 100).toFixed(2)}}%</td>
                <td>{{order.orderNo - order.successOrderNo}}</td>
                <td>{{(order.ordAmtSum - order.successOrdAmtSum).toFixed(2)}}</td>
                <td>
                    <button  :name="order.shortName" onclick="orderEcror(this.name)" v-if="order.shortName != '合计'">明细</button>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div style="text-align: right;margin-top: 10px;" id="pageDiv"></div>
</div>

<form action="${contextPath}/count/orderEcror" method="post" target="_blank" id="goToDetailPage"
      style="display:none">
    <input type="text" id="custCode" name="custCode" value="" style="display: none;">
    <textarea type="hidden" id="goToDetailPageData" name="rowData"></textarea>
</form>
<form action="${contextPath}/checking/exportExcel" method="post" id="exportExcel" style="display:none">
    <input type="hidden" name="tbcocompName" id="exportExcelParamTbcocompName">
    <input type="hidden" name="bankName" id="exportExcelParamBankName">
    <input type="hidden" name="merName" id="exportExcelParamMerName">
    <input type="hidden" name="settleDate" id="exportExcelParamSettleDate">
    <input type="hidden" name="payType" id="exportExcelParamPayType">
    <input type="hidden" name="tableType" value="general">
</form>
</body>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script type="text/javascript">
    var time = format(new Date(),"yyyy-MM-dd");
    console.log(time);

    var laypage = layui.laypage
        , layer = layui.layer;


    var queryModel = {
        turnCreateDate: time,
        bindCreateDate: time
    }



    var getOrder = function (queryModel) {
        console.log(queryModel);
        layer.load(1)
        $.ajax({
            url: '${contextPath}/count/getOrder', //localhost:8080
            type: 'post',
            data: queryModel,
            success: function (data) {
                layer.closeAll('loading');
                if (data.success == false) {
                    layer.msg("获取出错：" + data.message)
                    return
                }
                //console.log(data)
                var dataArray = data.data;
                if (dataArray.length == 0) {
                    layer.msg("查询没有数据")
                }
                dataArray = qui(dataArray);

                app.orderList = dataArray


                //console.log(data.data)
            },
            error: function (error) {
                layer.closeAll('loading');
                //console.log(error)
            }
        })
    }
    getOrder(queryModel)

    var queryOrder = function () {
        queryModel.turnCreateDate = $("#turnCreateDate").val()
        queryModel.bindCreateDate = $("#bindCreateDate").val()
        getOrder(queryModel)
    }


    <%--$.ajax({--%>
        <%--url: '${contextPath}/checking/getTbcocompNamesAndBankNamesAndMerNames', //--%>
        <%--type: 'post',--%>
        <%--data: queryModel,--%>
        <%--success: function (data) {--%>
            <%--if (data.success == false) {--%>
                <%--layer.msg("获取查询条件出错，请刷新页面")--%>
                <%--return--%>
            <%--}--%>
            <%--//console.log(data)--%>
            <%--var dataObj = data.data;--%>
            <%--app.turnCreateDate = dataObj.turnCreateDate--%>
            <%--app.bindCreateDate = dataObj.bindCreateDate--%>
        <%--},--%>
        <%--error: function (error) {--%>
            <%--//console.log(error)--%>
            <%--layer.msg("获取查询条件出错，请刷新页面")--%>
        <%--}--%>
    <%--})--%>

    $('#turnCreateDate').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });


    $('#bindCreateDate').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        minView: 2,
        showMeridian: 1,
        format: "yyyy-mm-dd",
//        startDate:new Date(),
    });

    var exportExcel = function () {
        $("#exportExcelParamTbcocompName").val(queryModel.tbcocompName)
        $("#exportExcelParamBankName").val(queryModel.bankName)
        $("#exportExcelParamMerName").val(queryModel.merName)
        $("#exportExcelParamSettleDate").val(queryModel.settleDate)
        $("#exportExcelParamPayType").val(queryModel.payType)

        $("#exportExcel").submit();
    }

    //***************** 明细 ************
    function orderEcror(shortName){
        window.location.href = "${contextPath}/count/orderEcror?shortName="+shortName;
    }

    //*******************************

    function qui(orderList) {
        var shortName = '合计';
        var orderNo = 0;
        var ordAmtSum = 0;
        var successOrderNo = 0;
        var successOrdAmtSum = 0;
//        console.log("orderList="+orderList.length);
        for (var i=0; i<orderList.length; i++){
            orderNo = orderList[i].orderNo + orderNo;
            ordAmtSum = orderList[i].ordAmtSum + ordAmtSum;
            successOrderNo = orderList[i].successOrderNo + successOrderNo;
            successOrdAmtSum = orderList[i].successOrdAmtSum + successOrdAmtSum;
        }
        var map = {"shortName" : shortName, "orderNo" : orderNo, "ordAmtSum" : ordAmtSum,
                    "successOrderNo" : successOrderNo, "successOrdAmtSum" : successOrdAmtSum}
//        console.log("map="+map.shortName+" "+map.ordAmtSum);
        orderList.push(map);
        return orderList;
    }

    //******************* 表头固定 *********************
    // Code goes here
    'use strict'
    window.onload = function(){
        var tableCont = document.querySelector('#tableContainer')
        /**
         * scroll handle
         * @param {event} e -- scroll event
         */
        function scrollHandle (e){
            console.log(this)
            var scrollTop = this.scrollTop;
            this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
        }

        tableCont.addEventListener('scroll',scrollHandle)
    }

    //****************************************

    $('#turnCreateDate').val(time);
    $('#bindCreateDate').val(time);
    function format(date,str){
        var mat={};
        mat.M=date.getMonth()+1;//月份记得加1
        mat.H=date.getHours();
        mat.s=date.getSeconds();
        mat.m=date.getMinutes();
        mat.Y=date.getFullYear();
        mat.D=date.getDate();
        mat.d=date.getDay();//星期几
        mat.d=check(mat.d);
        mat.H=check(mat.H);
        mat.M=check(mat.M);
        mat.D=check(mat.D);
        mat.s=check(mat.s);
        mat.m=check(mat.m);
        console.log(typeof mat.D)
        if(str.indexOf(":")>-1){
            mat.Y=mat.Y.toString().substr(2,2);
            return mat.Y+"/"+mat.M+"/"+mat.D;
        }
        if(str.indexOf("/")>-1){
            return mat.Y+"/"+mat.M+"/"+mat.D+" "+mat.H+"/"+mat.m+"/"+mat.s;
        }
        if(str.indexOf("-")>-1){
            return mat.Y+"-"+mat.M+"-"+mat.D;
        }
    }
    //检查是不是两位数字，不足补全
    function check(str){
        str=str.toString();
        if(str.length<2){
            str='0'+ str;
        }
        return str;
    }
</script>
</html>